package cn.xiu.drugstore.service.impl;

import java.util.List;

import cn.xiu.drugstore.dao.DrugDao;
import cn.xiu.drugstore.dao.impl.DrugDaoImpl;
import cn.xiu.drugstore.pojo.Drug;
import cn.xiu.drugstore.service.DrugService;
/**
 * 药品业务功能实现类
 * @author 柠夏初开
 *
 */
public class DrugSerciveImpl implements DrugService {
	private DrugDao drugDao=new DrugDaoImpl();
	/**
	 * 添加药品
	 */
	@Override
	public boolean publishDrug(Drug drug) {
		try {
			if(drugDao.addDrug(drug)==1){
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	/**
	 * 显示所有药品
	 */
	@Override
	public List<Drug> findAllDrug() {
		try {
			return drugDao.findAllDrug();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	/**
	 * 检查药品是否存在
	 */
	@Override
	public boolean checkDrugExists(String drugName) {
		Drug drug=null;
		try {
			drug=drugDao.queryByDrugName(drugName);
			if(drug!=null){
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	@Override
	public boolean findDrug(String drugId) {
		Drug drug=null;
		try {
			drug=drugDao.queryByDrugId(drugId);
			if(drug!=null){
				return true;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}

}
